package com.zhihao.takeaway.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhihao.takeaway.entity.BookAddressAndEmployeeAndMarketer;
import com.zhihao.takeaway.entity.Orders;
import com.zhihao.takeaway.entity.OrdersMarketerVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrdersMapper extends BaseMapper<Orders> {

    @Select("select orders.* ,marketer.image as image,marketer.store_name as storeName from orders,marketer where marketer.id = orders.marketer_id and orders.user_id = #{userId} and if(#{flag} = 'no',(orders.status = 1 or orders.status = 5)," +
                        "(orders.status = 2 or orders.status = 3 or orders.status = 4))")
    List<OrdersMarketerVo> selectOrdersAndDish(String userId, String flag);

//    用于根据条件查询订单订单
    @Select("select orders.id as orderId,orders.order_time as orderTime,address_book.consignee,address_book.phone as consigneePhone,address_book.province_name as consigneeProvince,"+
            "address_book.city_name as consigneeCity,address_book.district_name as consigneeDistrict,address_book.detail as consigneeDetail," +
            "address_book.label as consigneeLabel,marketer.name as marketerName,marketer.province_name as marketerProvince,marketer.city_name as marketerCity," +
            "marketer.district_name as marketerDistrict,marketer.detail as marketerDetail,marketer.label as marketerLabel,marketer.phone as marketerPhone" +
            " from address_book,marketer,orders where if(#{employeeId} is null,orders.employee_id is  null,orders.employee_id = #{employeeId}) and if(#{id} is null,orders.id is not null,orders.id = #{id})"+
            "  and orders.address_book_id = address_book.id and orders.marketer_id = marketer.id and orders.status = #{status} limit #{currentNum},#{wantNum}")
    List<BookAddressAndEmployeeAndMarketer> selectOrdersByCondition(Integer currentNum,String employeeId,Integer status,Integer wantNum,String id);
    @Select("select orders.id as orderId,orders.order_time as orderTime,address_book.consignee,address_book.phone as consigneePhone,address_book.province_name as consigneeProvince,"+
            "address_book.city_name as consigneeCity,address_book.district_name as consigneeDistrict,address_book.detail as consigneeDetail," +
            "address_book.label as consigneeLabel,marketer.name as marketerName,marketer.province_name as marketerProvince,marketer.city_name as marketerCity," +
            "marketer.district_name as marketerDistrict,marketer.detail as marketerDetail,marketer.label as marketerLabel,marketer.phone as marketerPhone" +
            " from address_book,marketer,orders where #{employeeId} = orders.employee_id and orders.status = #{status} and orders.address_book_id = address_book.id and orders.marketer_id = marketer.id")
    List<BookAddressAndEmployeeAndMarketer> selectOrdersWithoutLimit(String employeeId,Integer status);
    @Select("select orders.id as orderId,orders.order_time as orderTime,address_book.consignee,address_book.phone as consigneePhone,address_book.province_name as consigneeProvince,"+
            "address_book.city_name as consigneeCity,address_book.district_name as consigneeDistrict,address_book.detail as consigneeDetail," +
            "address_book.label as consigneeLabel,marketer.name as marketerName,marketer.province_name as marketerProvince,marketer.city_name as marketerCity," +
            "marketer.district_name as marketerDistrict,marketer.detail as marketerDetail,marketer.label as marketerLabel,marketer.phone as marketerPhone" +
            " from address_book,marketer,orders where orders.employee_id = #{employeeId} "+
            "  and orders.address_book_id = address_book.id and orders.marketer_id = marketer.id and orders.status = #{status} and orders.complete_time like '%' #{date} '%' limit #{currentNum},#{wantNum}")
    List<BookAddressAndEmployeeAndMarketer> selectOrdersByConditionWithTime(Integer currentNum, String employeeId, int status, int wantNum, String date);
}
